package rladidxo.basic;

import java.util.Scanner;


	public class Calendar
	{
	 static final int FEBRUARY        = 2;
	 static final int MONTHS_PER_YEAR = 12;
	 
	 static int [] daysPerMonth =
	  {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	 
	 static String [] months = 
	  {"", "  Januray", "February", "   March", "   April",
	    "      May", "    June", "    July", "  August",
	   "September", " October", "November", "December"};
	 
	 public static void main(String[] args)
	 {   
	  Scanner in = new Scanner(System.in);
	  System.out.print("Enter the year? (yyyy): ");
	  int year = in.nextInt();

	  int firstDay = firstDayOfYear(year);
	  
	  // February: Check for leap year   
	  daysPerMonth [FEBRUARY] = isLeapYear(year) ? 29 : 28;
	       
	  for (int i=1; i <= MONTHS_PER_YEAR; i++) {
	   Month month = new Month(daysPerMonth[i], firstDay);
	   System.out.println("\n\n      "+months[i]+" "+year);
	   month.printMonth();
	   firstDay = month.getFirstDayOfNextMonth();
	  }
	 }
	 
	 private static boolean isLeapYear(int year) {
	  return ((year%4 == 0) && (year%100 != 0)) || (year%400 == 0);
	 }

	 private static int firstDayOfYear(int year) {
	  return (2 * (13) + (3 * (13+1)/5) + (year-1) + ((year-1)/4)
	    - ((year-1)/100) + ((year-1)/400) + 2) % 7;
	 }
	}



